﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VideoClassLibrary.BusinessLogicLayer;
using System.Data;

public partial class NewsManagement_ViewNewsCategory : AdminUserBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {

            bindPageData();
        }
    }
    protected void pager_PageChanged(object sender, EventArgs e)
    {
        bindPageData();
    }

    private void bindPageData()
    {
        int schoolid = this.CurrentUser.SchoolID;
        NewsCategoryModule NM = new NewsCategoryModule();
        string sid="schoolid="+schoolid+" order by id desc";
        DataSet ds = NM.GetList(sid);
        this.repNews.DataSource = this.getPage(ds);
        this.repNews.DataBind();
    }

    public PagedDataSource getPage(DataSet ds)
    {
        this.pager.RecordCount = ds.Tables[0].Rows.Count;
        PagedDataSource pds = new PagedDataSource();
        pds.DataSource = ds.Tables[0].DefaultView;
        pds.AllowPaging = true;
        pds.CurrentPageIndex = pager.CurrentPageIndex - 1;
        pds.PageSize = pager.PageSize;
        return pds;
    }
    protected void btnDelete_Command(object sender, CommandEventArgs e)
    {

        int id = int.Parse(e.CommandArgument.ToString());
        NewsCategoryModule ncm = new NewsCategoryModule();
        ncm.DeleteNewsCategory(id);
        Response.Redirect("ViewNewsCategory.aspx");
    }
    /// <summary>
    /// 修改新闻
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    public void btnUpdate_Click(object sender, CommandEventArgs e)
    {
        Response.Redirect("UpdateNewsCategory.aspx?NID=" + e.CommandArgument.ToString());
    }
    protected void btnNews_Click(object sender, EventArgs e)
    {
        Response.Redirect("AddNews.aspx");
    }
}
